package com.returnsoft.softphone.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.returnsoft.softphone.dto.ServerDto;
import com.returnsoft.softphone.eao.ServerEao;
import com.returnsoft.softphone.entity.Server;
import com.returnsoft.softphone.exception.ConversionExcepcion;
import com.returnsoft.softphone.exception.CCenterExcepcion;
import com.returnsoft.softphone.exception.EaoExcepcion;
import com.returnsoft.softphone.util.Conversion;

/**
 * Session Bean implementation class ServerBean
 */
@Stateless
@LocalBean
public class ServerBean implements ServerInterface, Serializable {
	private static final long serialVersionUID = 1L;
	@EJB
	private ServerEao eao;
	@EJB
	private Conversion conv;
	
	/*@Override
	public List<ServerDto> findAll() throws CustomExcepcion {
		try {
			List<Server> servers = eao.findAll();
			List<ServerDto> serversDto = new ArrayList<ServerDto>();
			for (Server server : servers) {
				ServerDto serverDto = conv.fromServer(server);
				serversDto.add(serverDto);
			}
			return serversDto;
		} catch (Exception e) {
			throw new CustomExcepcion(e.getMessage());
		}
	}*/
	
	@Override
	public ServerDto findByCode(String code) throws CCenterExcepcion {
		try {
			Server server = eao.findByCode(code);
			return conv.fromServer(server);
		} catch (EaoExcepcion e) {
			throw new CCenterExcepcion(e.getMessage());
		} catch (ConversionExcepcion e) {
			throw new CCenterExcepcion(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			throw new CCenterExcepcion(e.getMessage());
		}
	}

}
